//深度优先遍历: 尽可能深的搜索树的分支
// 比喻：类似读书 把每章节读完再去读下一章节

//算法口诀
//1、先访问根节点
//2、对根节点的children 挨个进行深度优先遍历

const tree = {
   val:'a',
   children:[
     {
        val:'b',
        children:[
            {
                val:'d',
                children:[
                    {
                        val:'h',
                        children:[]
                    },
                    {
                        val:'i',
                        children:[]
                    }
                ]
            },
            {
                val:'e',
                children:[]
            }
        ]
     },
     {
        val:'c',
        children:[
            {
                val:'f',
                children:[]
            },
            {
                val:'g',
                children:[]
            }
        ]
     }
   ]
}


const dfs = (root)=>{
    //使用递归遍历
    console.log(root.val);
    //遍历根节点的child
    root.children.forEach(child=>{dfs(child)})
}

dfs(tree)